package com.onpositive.datacollection.editor;

import org.eclipse.swt.widgets.Display;

import com.onpositive.commons.elements.BrowserElement;
import com.onpositive.datamap.core.IDataObject;
import com.onpositive.datamap.core.IImageObject;
import com.onpositive.datamap.core.impl.DataObject;
import com.onpositive.semantic.model.ui.roles.ImageObject;
import com.onpositive.semantic.ui.workbench.elements.SelectionView;

public class TC extends CollectionBasedSelectionView{

	private IImageObject primaryImage;

	public TC(){
		super("tc.dlf");
		setAsync(true);
	}
	@Override
	protected Object transform(Object value) {
		
		final DataObject o=(DataObject) value;
		Display.getDefault().asyncExec(new Runnable() {
			
			@Override
			public void run() {
				if (o==null){
					return;
				}
				BrowserElement bw= (BrowserElement) getElement("2");
				bw.setUrl("http://en.wikipedia.org/wiki/"+o.getUID());
			}
		});
		if (o==null){
			return "";
		}
		
		primaryImage = o.getPrimaryImage();
		return o.getTextContentAsString();
	}
	
	public byte[] getImage(){
		if (primaryImage!=null){
			byte[] bytes = primaryImage.getBytes(-1, -1);
			if (bytes!=null){
				
			}
		}
		return null;		
	}

	@Override
	protected Class getTargetClass() {
		return IDataObject.class;
	}
}
